#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：图灵学习 
@File    ：9.队列信号.py
@IDE     ：PyCharm 
@Author  ：ChenLiGao
@Date    ：2024-11-06 10:06
'''
from multiprocessing import Process, JoinableQueue

import requests # 同步网络爬虫库：第三方包，需要自己下载
url_list = [
    "https://ww2.sinaimg.cn/mw690/008Dx8Yely1hre748fydoj30u00k0q65.jpg",
    "https://ww4.sinaimg.cn/mw690/008Dx8Yely1hrniembn9pj30gf0g8tbv.jpg",
    "https://wx1.sinaimg.cn/mw690/008Dx8Yely1hrp5nr0s79j30og0ogn08.jpg",
]

def get_image(queue:JoinableQueue, file_name):
    url = queue.get()
    response = requests.get(url).content
    with open("9images/"+str(file_name)+".png", mode="wb") as file:
        file.write(response)

if __name__ == '__main__':
    queue = JoinableQueue()
    for url in url_list:
        queue.put(url)

    for i in range(queue.qsize()):
        p = Process(target=get_image, args=(queue, i))
        p.daemon = True
        p.start()


